<?php
class UserShareAction extends UAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'tpl';
		$this->layout = 'uindex';
		$this->data['menu']	= 'share';
	}

	public function execute()
	{
		$con 			= array();
		$con['userid'] 	= $this->user_id;
		$page 			= $this->getPage();
		$pageSize 		= 20;
		
		//搜索分享
		$shareService = new ShareService('share');
		$result = $shareService->query($con, $page, $pageSize);
		$totalNum = $result['totalNum'];
		$this->data['column'] = $result['list'];
		$ids = array();
		if(!empty($this->data['column']))
		{
			foreach($this->data['column'] as $lv)
			{
				$ids[] = $lv['id'];
			}
		}
		
		if ($ids){
			$tmp = $shareService->rows(array('id'=>array('in'=>$ids)), '', array('id','collect_num','comment_num'));
			$result = array();
			foreach($tmp as $v){
				$result[$v['id']] = $v;
			}
			
			foreach($this->data['column'] as $sk=>$share){
				foreach($share as $k=>$item){
					$share[$k]['collect_num'] = (int)$result[$item['share_id']]['collect_num'];
					$share[$k]['comment_num'] = (int)$result[$item['share_id']]['comment_num'];
				}
				$this->data['column'][$sk] = $share;
			}
			
		}
		
		$ltConfig		= C('LtConfig');
		$pagerConfig	= $ltConfig->get('pagination.pager');
		$baseUrl 		= C('LtUrl')->generate('Default', 'Index', array('module'=>'User','action'=>'Collect','uid'=>$this->user_id,'p' => ':page'));
		$pagination 	= new PiscesPagination;
		$pagination->init($pagerConfig);
		$this->data['pages'] = $pagination->pager($page, $totalNum, $baseUrl);
		$this->data['items'] = $rows;
		
	}
}
